package com.irdstudio.efp.riskm.service.impl;

import com.irdstudio.basic.framework.core.base.FrameworkService;
import com.irdstudio.efp.riskm.service.dao.RscWarnGnlHistDataDao;
import com.irdstudio.efp.riskm.service.domain.RscWarnGnlHistData;
import com.irdstudio.efp.riskm.service.facade.RscWarnGnlHistDataService;
import com.irdstudio.efp.riskm.service.vo.RscWarnGnlHistDataVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * 需求编号：【2019D0509】（业务提的需求编号）
 * 问题编号：【】（若不是因为修复问题而新增该类，则留空）
 * 开发人员：【wanglh4】
 * 创建日期：【2019/11/20 12:35】
 * 功能描述：
 */
@Service("rscWarnGnlHistDataService")
public class RscWarnGnlHistDataServiceImpl implements RscWarnGnlHistDataService, FrameworkService {

    private static Logger logger = LoggerFactory.getLogger(RscWarnGnlHistDataServiceImpl.class);

    @Autowired
    private RscWarnGnlHistDataDao rscWarnGnlHistDataDao;

    @Override
    public RscWarnGnlHistDataVO queryByCusId(RscWarnGnlHistDataVO rscWarnGnlHistDataVO) {
        logger.debug("当参数信息为:" + rscWarnGnlHistDataVO);
        List<RscWarnGnlHistDataVO> list = null;
        try{
            RscWarnGnlHistData rscWarnGnlHistData = new RscWarnGnlHistData();
            beanCopy(rscWarnGnlHistData,rscWarnGnlHistDataVO);
            RscWarnGnlHistData queryRsRscWarnGnlHistData= rscWarnGnlHistDataDao.queryByCusId(rscWarnGnlHistData);
            if (Objects.nonNull(queryRsRscWarnGnlHistData)) {
                RscWarnGnlHistDataVO outRscWarnGnlHistDataVO = beanCopy(queryRsRscWarnGnlHistData,new  RscWarnGnlHistDataVO());
                logger.debug("当前查询结果为:"+ outRscWarnGnlHistDataVO.toString());
                return outRscWarnGnlHistDataVO;
            } else {
                logger.debug("当前查询结果为空!");
            }
        } catch (Exception e) {
            logger.error("数据转换出现异常!", e);
        }
        return null;
    }

    @Override
    public int updateByTaskNo(RscWarnGnlHistDataVO rscWarnGnlHistDataVO) {
        logger.debug("当前查询本人所属数据信息的参数信息为:" + rscWarnGnlHistDataVO);
        int num = 0;
        try {
            RscWarnGnlHistData rscWarnGnlHistData = new RscWarnGnlHistData();
            beanCopy(rscWarnGnlHistDataVO,rscWarnGnlHistData);
            num = rscWarnGnlHistDataDao.updateByTaskNo(rscWarnGnlHistData);
        } catch (Exception e) {
            e.printStackTrace();
            num = -1;
            logger.error("数据转换出现异常!", e.getMessage());
        }
        return num;
    }

    @Override
    public int insertByTaskNo(RscWarnGnlHistDataVO rscWarnGnlHistDataVO) {
        logger.info("当参数信息为:" + rscWarnGnlHistDataVO);
        int num = 0;
        try {
            RscWarnGnlHistData rscWarnGnlHistData = new RscWarnGnlHistData();
            beanCopy(rscWarnGnlHistDataVO,rscWarnGnlHistData);
            num = rscWarnGnlHistDataDao.insertByTaskNo(rscWarnGnlHistData);
        } catch (Exception e) {
            num = -1;
            logger.error("数据转换出现异常!", e.getMessage());
        }
        return num;
    }
}
